/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-10-25 13:48:18
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2024-10-29 09:23:45
 * @FilePath: /src/cloud.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include "util.hpp"
#include "Data.hpp"
#include "hot.hpp"
#include "server.hpp"
void FileUtilTest(const std::string &filename)
{
    cloud::FileUtil fu(filename);
    //std::cout << fu.FileName() << " " << fu.FileSize() << " " << fu.LastAccTime() << " " <<fu.LastModTime() <<std::endl;
    fu.CreateDirectory();
    std::vector<std::string> arry;
    fu.ScanDirectory(&arry);

    for (auto& e : arry)
    {
        std::cout << e << std::endl;
    }
    

}

void DataTest(const std::string &filename)
{
    cloud::BackupInfo info;
    info.NewBackupInfo(filename);
    cloud::DataManager manager;
    manager.Insert(info);


    cloud::BackupInfo tmp;
    manager.GetOneByURL("/download/test.txt" , &tmp);

    std::cout << "----------URL----------" << std::endl; 
    std::cout << tmp.pack_flag << std::endl;
    std::cout << tmp.atime << std::endl;
    std::cout << tmp.mtime << std::endl;
    std::cout << tmp.fsize << std::endl;
    std::cout << tmp.pack_path << std::endl;
    std::cout << tmp.real_path << std::endl;
    std::cout << tmp.url << std::endl;

    info.pack_flag = true;
    manager.Update(info);
    std::vector<cloud::BackupInfo> arry;
    manager.GetAll(&arry);
    std::cout << "----------updata and getall----------" << std::endl; 

    for (auto &a : arry)
    {
    std::cout << a.pack_flag << std::endl;
    std::cout << a.atime << std::endl;
    std::cout << a.mtime << std::endl;
    std::cout << a.fsize << std::endl;
    std::cout << a.pack_path << std::endl;
    std::cout << a.real_path << std::endl;
    std::cout << a.url << std::endl;            
    }
    std::cout << "----------realpath----------" << std::endl; 
    manager.GetOneByRealPath(filename , &tmp);
    std::cout << tmp.pack_flag << std::endl;
    std::cout << tmp.atime << std::endl;
    std::cout << tmp.mtime << std::endl;
    std::cout << tmp.fsize << std::endl;
    std::cout << tmp.pack_path << std::endl;
    std::cout << tmp.real_path << std::endl;
    std::cout << tmp.url << std::endl;

}
void test1(const std::string &filename)
{
    cloud::DataManager manager;
    std::vector<cloud::BackupInfo> arry;
    manager.GetAll(&arry);
    for (auto &a : arry)
    {
    std::cout << a.pack_flag << std::endl;
    std::cout << a.atime << std::endl;
    std::cout << a.mtime << std::endl;
    std::cout << a.fsize << std::endl;
    std::cout << a.pack_path << std::endl;
    std::cout << a.real_path << std::endl;
    std::cout << a.url << std::endl;            
    }
    
}



cloud::DataManager *_data;
void testHot()
{                         
    cloud::HotManager hotmanager;
    hotmanager.RunModule();
}

void testServer()
{
    cloud::Service srv;
    srv.RunModule();
}
int main()
{
    _data = new cloud::DataManager();
    //FileUtilTest(argv[1]);
    //DataTest("./test.txt");
    // cloud::FileUtil fu("./cloud.dat");
    //fu.SetContent("111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
    //test1(argv[1]);
    //testHot();
    testServer();
    return 0;
}